const learnpath = require("../models/learnpath")

var express = require('express');
var router = express.Router();

const formidable = require('formidable');

//返回图片
router.post('/', (req, res, next) => {
    var form = new formidable.IncomingForm();
    form.parse(req, function (err, fields, files) {
        if (err) {
            res.json({ 'state': false })
        } else {
          learnpath.find({}, (error, doc) => {
              console.log(doc)
                if (error) {
                    res.json({ 'state': false, 'msg': error });
                } else {
                    let result = [];
                    doc.forEach(learn => {
                        if(learn.flags.every(val => fields.flags.includes(val))){
                            result.push(learn);
                        }
                    });
                    res.json({
                        'state': true,
                        'learn_path': result
                    })
                }
            })

        }

    });

});

module.exports = router;